import 'dart:io';
import 'dart:async';

import 'dart:isolate';

main(List<String> args) {
  test_isolates();
}

class Spacecraft {
  String name;
  DateTime? launchDate;

  Spacecraft(this.name, this.launchDate);

  Spacecraft.unlaunched(String name) : this(name, null);
  // Spacecraft(String name) : this(name, null);

  int get launchYear => launchDate!.year;

  void describe() {
    print("Spacecraft: $name");
    if (launchDate != null) {
      var years = DateTime.now().difference(launchDate!).inDays;
      print("Send Time: $launchYear ($years years age)");
    } else {
      print("Hasn't Send");
    }
  }
}

void test_sync() {
  print("Enter your name:");

  var name = stdin.readLineSync();

  print("Hello Mr. $name");
  print("End of main");
}

void test_async() {
  var file = File(Directory.current.path + "/contact.txt");
  file.readAsString().then((value) => print(value));

  print("End of test_async");
}

void foo(String msg) {
  print("The message is : ${msg}");
}

void test_isolates() {
  Isolate.spawn(foo, "Hello!!");
  Isolate.spawn(foo, "Greetings!!");
  Isolate.spawn(foo, "Welcome!!");

  print("execution from main1");
  print("execution from main2");
  print("execution from main3");
}
